home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 …ember: Reference Library / Dev.CD Dec 00 RL Disk 1.toast / pc / technical documentation / develop / additional articles / timing on the macintosh / timing code / src / microseconddelta.c next >
Encoding:
C/C++ Source or Header  |  1995-04-17  |  1.0 KB  |  45 lines

  1. /*                                    MicrosecondDelta.c                                */
  2. /*
  3.  * MicrosecondDelta.c
  4.  * Copyright © 1994 Apple Computer Inc.
  5.  */
  6. #include "MicrosecondTrap.h"
  7.  
  8. /*
  9.  * Convert an epoch to microseconds (use floating-point operations).
  10.  * Note that 4294967296.0 is 2^32, which is represented accurately
  11.  * in double-precision floating point. Note that this can loose
  12.  * low-order bits.
  13.  */
  14. #define kTwoPower32 (4294967296.0)
  15.  
  16. double
  17. MicrosecondToDouble(
  18.         register const UnsignedWide    *epochPtr
  19.     )
  20. {
  21.         register double            result;
  22.         
  23.         result = (((double) epochPtr->hi) * kTwoPower32) + epochPtr->lo;
  24.         return (result);
  25. }
  26.  
  27. /*
  28.  * Return the difference between two Microsecond Trap values.
  29.  * Integer subtraction is used to preserve accuracy.
  30.  */
  31. void
  32. MicrosecondDelta(
  33.         register const UnsignedWide    *startPtr,
  34.         register const UnsignedWide    *endPtr,
  35.         register UnsignedWide        *result
  36.     )
  37. {
  38.         if (endPtr->lo >= startPtr->lo)
  39.             result->hi = endPtr->hi - startPtr->hi;
  40.         else {
  41.             result->hi = (endPtr->hi - 1) - startPtr->hi;
  42.         }
  43.         result->lo = endPtr->lo - startPtr->lo;
  44. }
  45.